When you create a new ASP.NET Web Site project, your project may contain any number of specifically named subdirectories, each of which has a special meaning to the ASP.NET runtime. Table 32-3 documents these special subdirectories.
Table 32-3. Special ASP.NET Subdirectories
Subfolder |
Meaning in Life |
---|---|
App_Browsers |
Folder for browser definition files that are used to identify individual browsers and determine their capabilities |
App_Code |
Folder for source code for components or classes that you want to compile as part of your application. ASP.NET compiles the code in this folder when pages are requested. Code in the App_Code folder is automatically accessible by your application |
App_Data |
Folder for storing Access *.mdb files, SQL Express *.mdf files, XML files, or other data stores |
App_GlobalResources |
Folder for *.resx files that are accessed programmatically from application code |
App_LocalResources |
Folder for *.resx files that are bound to a specific page |
App_Themes |
Folder that contains a collection of files that define the appearance of ASP.NET web pages and controls |
App_WebReferences |
Folder for proxy classes, schemas, and other files associated with using a web service in your application |
Bin |
Folder for compiled private assemblies (*.dll files). Assemblies in the Bin folder are automatically referenced by your application |
If you are interested in adding any of these known subfolders to your current web application, you may do so explicitly using the Website > Add Folder menu option. However, in many cases, the IDE will automatically do so as you naturally insert related files into your site. For example, inserting a new class file into your project will automatically add an App_Code folder to your directory structure if one does not currently exist.
Although the Web Site templates do generate an *.sln file to load your *.aspx files into the IDE, there is no longer a related *.csproj file. However, an ASP.NET Web Application projects records all external assemblies within *.csproj. So where are the external assemblies recorded under ASP.NET?
As you have seen, when you reference a private assembly, Visual Studio 2010 will automatically create a \bin directory within your directory structure to store a local copy of the binary. When your code base makes use of types within these code libraries, they are automatically loaded on demand.
If you reference a shared assembly located in the Global Assembly Cache, Visual Studio 2010 will automatically insert a Web.config file into your current web solution (if one is not currently in place) and record the external reference within the <assemblies> element. For example, if you again activate the Web Site > Add Reference menu option and this time select a shared assembly (such as System.Data.OracleClient.dll), you will find that your Web.config file has been updated as follows:
<assemblies> <add assembly="System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> </assemblies>
As you can see, each assembly is described using the same information required for a dynamic load via the Assembly.Load() method (see Chapter 15).
The App_Code folder is used to store source code files that are not directly tied to a specific web page (such as a code-behind file) but are to be compiled for use by your website. Code within the App_Code folder will be automatically compiled on the fly on an as-needed basis. After this point, the assembly is accessible to any other code in the website. To this end, the App_Code folder is much like the Bin folder, except that you can store source code in it instead of compiled code. The major benefit of this approach is that it is possible to define custom types for your web application without having to compile them independently.
A single App_Code folder can contain code files from multiple languages. At runtime, the appropriate compiler kicks in to generate the assembly in question. If you would rather partition your code, however, you can define multiple subdirectories that are used to hold any number of managed code files (*.vb, *.cs, etc.).
For example, assume you have added an App_Code folder to the root directory of a website application that has two subfolders, MyCSharpCode and MyVbNetCode, that contain language-specific files. Once you do, you are able to update your Web.config file to specify these subdirectories using a <codeSubDirectories> element nested within the <configuration> element:
<compilation debug="true" strict="false" explicit="true"> <codeSubDirectories> <add directoryName="MyCSharpCode" /> <add directoryName="MyVbNetCode" /> </codeSubDirectories> </compilation>
Note The App_Code directory will also be used to contain files that are not language files but are useful nonetheless (*.xsd files, *.wsdl files, etc.).
Beyond Bin and App_Code, the App_Data and App_Themes folders are two additional special subdirectories that you should be familiar with, both of which will be detailed in the next several chapters. As always, consult the .NET Framework 4.0 SDK documentation for full details of the remaining ASP.NET subdirectories if you require further information.